{% extends 'base_event.html' %}
{% block title %} Event Details {% endblock %}

{% block bannerMsg %}
<div id='navDiv'><a href="/goToMain">Return To Calendar</a> </div>
<div id='userNameDiv'><a href="/doLogout">Logout</a> </div>
<div id='userNameDiv'><b>Welcome: </b>  {{sess_fullname}} </div>
{% endblock %}




{% block ctrlContent %}
	{% include 'schedule.html' %}
{% endblock %}
{% block eventShow %}

<div id="errorDiv"></div>
<div id="eventHdr" ><h3>Event Details: {{Event.title}}</h3> </div>

<div id="eventDetails">
	<table>
	<tr>
		<td>Coordinator:</td>
		<td>{{Event.hostName}}</td>
	</tr>
	<tr>
		<td>Location:</td>
		<td>{{Event.room}} - {{Event.rDesc}}</td>
	</tr>
	<tr>
		<td>Start Time:</td>
		<td>{{Event.startDt}}</td>
	</tr>
	<tr>
		<td>End Time:</td>
		<td>{{Event.endDt}}</td>
	</tr>
	<tr>
		<td>Event Status:</td>
		<td>{{Event.eventStatusDesc}}</td>
	</tr>
</table>	
	
	
</div>


<div> Attendee(s): {{eName}}</div>
<div id="eventAttdList">
<table>
	<tr>
		<th>Attendee Name</th>
		<th>Status</th>
		
	</tr>

{% for user in Attendees %}
	
	<tr>
		
		<td>{{user.listName}}</td><td>{{user.statusDesc}}</td>
	</tr>
{% endfor %}
</form>
</table>
</div>
{% endblock %}



{% block eventMenu %}
	<!-- This is eventMenu-->
	{% if _CORD_  is defined %}
		<!-- Another in  eventMenu-->

		<div id="eventControls">
			<form action="" id="cordEvent"  method="post">
				<input type="hidden" name="EventID" id="eventId" value="{{Event.eventID}}" />
				<input type="hidden" name="EventStart" id="startTime" value="{{Event.start}}" />
				<input type="hidden" name="title" value="{{Event.title}}" />
				
				{% for user in Attendees %}
					<input type="hidden" name="email" value="{{user.userID}}" />
				{% endfor %}
				<input type="button" id="cordCancelBtn" value="Cancel Meeting" />
				<input type="button" id="cordEditBtn" value="Edit Meeting" />
			</form>
		</div>
	{% else %}
		<div id="eventControls">
			<form action="" id="attEvent"  method="post">
				<input type="hidden" name="EventID" value="{{Event.eventID}}" />
				<input type="hidden" name="UID" value="{{UID}}" />
				<input type="button" id="attAcceptBtn" value="Accept Invite" />
				<input type="button" id="attDeclineBtn" value="Decline Invite" />
			</form>
		</div>
		
	
	{% endif %}	
	

{% endblock %}


{% block jscript %}

	{% if _CORD_  is defined %}
		<script>
			$(document).ready(function() {
				
				$("input[id=cordCancelBtn]").click(function() {
					var timestamp = Math.round(new Date().getTime() / 1000);
					
					var mstart = $("#startTime").val();
					
					if (timestamp >= mstart  ) {
						alert("Notice: Notice: Event is in the past\n\nEvent can not be canceled");
					} else {
						$.ajax({
							url: "/ws/eventCancel",
							//dataType: 'json',
							async: false,
							data: $("#cordEvent :input").serialize(),
							
						});
						location.reload();
					}
				});
				
				// Add handler for edit button
				$("input[id=cordEditBtn]").click(function() {
					// Show the edit interface...
					var timestamp = Math.round(new Date().getTime() / 1000);
					var mstart = $("#startTime").val();
					var mid = $("#eventId").val();
					if (timestamp >= mstart  ) {
						alert("Notice: Event is in the past\n\nEvent can not be edited...");
					} else {
						
						$(".tabHead").html('Edit Existing Meeting');
						$("#eSubmit").hide();
						$("#eReset").hide();
						// set the form id on a hidden field
						$("#updateEventID").val(mid);
						
						$("#updateEventBtn").show();
						
						// get event and attendee information
						//alert("MID = " + mid);
						$.ajax({
							url: "/ws/getEventById",
							dataType: 'json',
							//async: false,
							data: {'EventID': mid},
							success: function(response) {
								// set form values
								/*
								 * Event Data => {"mdescription": "Finish Paper", 
								 * "mroomid": 14, 
								 * "mid": 80, 
								 * "mendtime": 1314842400, 
								 * "ATTEND_LIST": 
								 * [{"asid": 0, "mid": 80, "uid": 2}, {"asid": 0, "mid": 80, "uid": 3}], 
								 * "mstatusid": 1, 
								 * "mhostid": 1, 
								 * "mstarttime": 1314838800}

								 * 
								 */
								$("#eventDescID").val(response['mdescription']);
								$("#eStrtId").val(response['START']);
								
								//$('#selRoomId').attr('checked','checked')
								$("#selRoomId").val(response['mroomid']);
								
								var userList =new Array();
								$.each(response['ATTEND_LIST'], function(row, data){
									//alert("USER: " + data['uid'])
									userList.push(data['uid'])
								});
								$("#selUserId").val(userList);
								
								$("#eStrtTimeHr").val(response['START_HR']);
								$("#eStrtTimeMin").val(response['START_MIN']);
								$("#eStrtTimeMer").val(response['MER']);
								$("#eDurHr").val(response['DUR_HR']);
								$("#eDurMin").val(response['DUR_MIN']);	
							}
						});			
						$('#ctrlDiv').fadeIn(2000);
					}
				});
			
				$("input[id=updateEventBtn]").click(function() {
					//alert("Clicked");
					$.ajax({
						url: "/ws/updateEvent",
						async: false,
						data: $("#createEvent :input").serialize(),
					});
					
					
					// reload the page after the update...
					location.reload();
				});
			
			
			
			});
		</script>
		
	{% else %}
		<script>
			$(document).ready(function() {
				$("input[id=attAcceptBtn]").click(function() {
					$.ajax({
						url: "/ws/eventAccept",
						async: false,
						data: $("#attEvent :input").serialize(),
					});
					location.reload();
				});
				
				$("input[id=attDeclineBtn]").click(function() {
					$.ajax({
						url: "/ws/eventDecline",
						async: false,
						data: $("#attEvent :input").serialize(),
					});
					location.reload();
				});
			
			
			});
		</script>
		
	
	{% endif %}	

{% endblock%}




